package Stream;

/**
 * Created by Think on 2016/4/9.
 */
import java.io.*;
public class Member2 implements Serializable  {
    private String number;
    private String name;
    private int age;

    public Member2(String number, String name, int age){
        this.number = number;
        this.name = name;
        this.age = age;
    }
    // 部分程序代码省略,因为只一些Getter、Setter...
    @Override
    public String toString() {
        return String.format("(%s, %s, %d)", number, name, age);
    }
    public void save() {
        try(ObjectOutputStream output =
                    new ObjectOutputStream(new FileOutputStream(number))) {
            output.writeObject(this);
        } catch(IOException ex) {
            throw new RuntimeException(ex);
        }
    }
    public static Member2 load(String number) {
        Member2 member = null;
        try(ObjectInputStream input =
                    new ObjectInputStream(new FileInputStream(number))) {
            member = (Member2) input.readObject();
        } catch(IOException | ClassNotFoundException ex) {
            throw new RuntimeException(ex);
        }
        return member;
    }
}
